home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tclInt.h < prev    next >
C/C++ Source or Header  |  1993-07-07  |  36KB  |  922 lines

  1. /*
  2.  * tclInt.h --
  3.  *
  4.  *    Declarations of things used internally by the Tcl interpreter.
  5.  *
  6.  * Copyright (c) 1987-1993 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Permission is hereby granted, without written agreement and without
  10.  * license or royalty fees, to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose, provided that the
  12.  * above copyright notice and the following two paragraphs appear in
  13.  * all copies of this software.
  14.  * 
  15.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  16.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  17.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  18.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19.  *
  20.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  21.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  22.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  23.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  24.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  25.  *
  26.  * $Header: /user6/ouster/tcl/RCS/tclInt.h,v 1.84 93/07/07 16:24:38 ouster Exp $ SPRITE (Berkeley)
  27.  */
  28.  
  29. #ifndef _TCLINT
  30. #define _TCLINT
  31.  
  32. /*
  33.  * Common include files needed by most of the Tcl source files are
  34.  * included here, so that system-dependent personalizations for the
  35.  * include files only have to be made in once place.  This results
  36.  * in a few extra includes, but greater modularity.  The order of
  37.  * the three groups of #includes is important.  For example, stdio.h
  38.  * is needed by tcl.h, and the _ANSI_ARGS_ declaration in tcl.h is
  39.  * needed by stdlib.h in some configurations.
  40.  */
  41.  
  42. #include <stdio.h>
  43.  
  44. #ifndef _TCL
  45. #include "tcl.h"
  46. #endif
  47. #ifndef _REGEXP
  48. #include "regexp.h"
  49. #endif
  50.  
  51. #include <ctype.h>
  52. #ifdef NO_LIMITS_H
  53. #   include "compat/limits.h"
  54. #else
  55. #   include <limits.h>
  56. #endif
  57. #ifdef NO_STDLIB_H
  58. #   include "compat/stdlib.h"
  59. #else
  60. #   include <stdlib.h>
  61. #endif
  62. #ifdef NO_STRING_H
  63. #include "compat/string.h"
  64. #else
  65. #include <string.h>
  66. #endif
  67. #include <varargs.h>
  68.  
  69. /*
  70.  * At present (12/91) not all stdlib.h implementations declare strtod.
  71.  * The declaration below is here to ensure that it's declared, so that
  72.  * the compiler won't take the default approach of assuming it returns
  73.  * an int.  There's no ANSI prototype for it because there would end
  74.  * up being too many conflicts with slightly-different prototypes.
  75.  */
  76.  
  77. extern double strtod();
  78.  
  79. /*
  80.  *----------------------------------------------------------------
  81.  * Data structures related to variables.   These are used primarily
  82.  * in tclVar.c
  83.  *----------------------------------------------------------------
  84.  */
  85.  
  86. /*
  87.  * The following structure defines a variable trace, which is used to
  88.  * invoke a specific C procedure whenever certain operations are performed
  89.  * on a variable.
  90.  */
  91.  
  92. typedef struct VarTrace {
  93.     Tcl_VarTraceProc *traceProc;/* Procedure to call when operations given
  94.                  * by flags are performed on variable. */
  95.     ClientData clientData;    /* Argument to pass to proc. */
  96.     int flags;            /* What events the trace procedure is
  97.                  * interested in:  OR-ed combination of
  98.                  * TCL_TRACE_READS, TCL_TRACE_WRITES, and
  99.                  * TCL_TRACE_UNSETS. */
  100.     struct VarTrace *nextPtr;    /* Next in list of traces associated with
  101.                  * a particular variable. */
  102. } VarTrace;
  103.  
  104. /*
  105.  * When a variable trace is active (i.e. its associated procedure is
  106.  * executing), one of the following structures is linked into a list
  107.  * associated with the variable's interpreter.  The information in
  108.  * the structure is needed in order for Tcl to behave reasonably
  109.  * if traces are deleted while traces are active.
  110.  */
  111.  
  112. typedef struct ActiveVarTrace {
  113.     struct Var *varPtr;        /* Variable that's being traced. */
  114.     struct ActiveVarTrace *nextPtr;
  115.                 /* Next in list of all active variable
  116.                  * traces for the interpreter, or NULL
  117.                  * if no more. */
  118.     VarTrace *nextTracePtr;    /* Next trace to check after current
  119.                  * trace procedure returns;  if this
  120.                  * trace gets deleted, must update pointer
  121.                  * to avoid using free'd memory. */
  122. } ActiveVarTrace;
  123.  
  124. /*
  125.  * The following structure describes an enumerative search in progress on
  126.  * an array variable;  this are invoked with options to the "array"
  127.  * command.
  128.  */
  129.  
  130. typedef struct ArraySearch {
  131.     int id;            /* Integer id used to distinguish among
  132.                  * multiple concurrent searches for the
  133.                  * same array. */
  134.     struct Var *varPtr;        /* Pointer to array variable that's being
  135.                  * searched. */
  136.     Tcl_HashSearch search;    /* Info kept by the hash module about
  137.                  * progress through the array. */
  138.     Tcl_HashEntry *nextEntry;    /* Non-null means this is the next element
  139.                  * to be enumerated (it's leftover from
  140.                  * the Tcl_FirstHashEntry call or from
  141.                  * an "array anymore" command).  NULL
  142.                  * means must call Tcl_NextHashEntry
  143.                  * to get value to return. */
  144.     struct ArraySearch *nextPtr;/* Next in list of all active searches
  145.                  * for this variable, or NULL if this is
  146.                  * the last one. */
  147. } ArraySearch;
  148.  
  149. /*
  150.  * The structure below defines a variable, which associates a string name
  151.  * with a string value.  Pointers to these structures are kept as the
  152.  * values of hash table entries, and the name of each variable is stored
  153.  * in the hash entry.
  154.  */
  155.  
  156. typedef struct Var {
  157.     int valueLength;        /* Holds the number of non-null bytes
  158.                  * actually occupied by the variable's
  159.                  * current value in value.string (extra
  160.                  * space is sometimes left for expansion).
  161.                  * For array and global variables this is
  162.                  * meaningless. */
  163.     int valueSpace;        /* Total number of bytes of space allocated
  164.                  * at value.string.  0 means there is no
  165.                  * space allocated. */
  166.     union {
  167.     char *string;        /* String value of variable, used for scalar
  168.                  * variables and array elements.  Malloc-ed. */
  169.     Tcl_HashTable *tablePtr;/* For array variables, this points to
  170.                  * information about the hash table used
  171.                  * to implement the associative array. 
  172.                  * Points to malloc-ed data. */
  173.     struct Var *upvarPtr;    /* If this is a global variable being
  174.                  * referred to in a procedure, or a variable
  175.                  * created by "upvar", this field points to
  176.                  * the record for the higher-level variable. */
  177.     } value;
  178.     Tcl_HashEntry *hPtr;    /* Hash table entry that refers to this
  179.                  * variable, or NULL if the variable has
  180.                  * been detached from its hash table (e.g.
  181.                  * an array is deleted, but some of its
  182.                  * elements are still referred to in upvars). */
  183.     int refCount;        /* Counts number of active uses of this
  184.                  * variable, not including its main hash
  185.                  * table entry: 1 for each additional variable
  186.                  * whose upVarPtr points here, 1 for each
  187.                  * nested trace active on variable.  This
  188.                  * record can't be deleted until refCount
  189.                  * becomes 0. */
  190.     VarTrace *tracePtr;        /* First in list of all traces set for this
  191.                  * variable. */
  192.     ArraySearch *searchPtr;    /* First in list of all searches active
  193.                  * for this variable, or NULL if none. */
  194.     int flags;            /* Miscellaneous bits of information about
  195.                  * variable.  See below for definitions. */
  196. } Var;
  197.  
  198. /*
  199.  * Flag bits for variables:
  200.  *
  201.  * VAR_ARRAY    -        1 means this is an array variable rather
  202.  *                than a scalar variable.
  203.  * VAR_UPVAR -             1 means this variable just contains a
  204.  *                pointer to another variable that has the
  205.  *                real value.  Variables like this come
  206.  *                about through the "upvar" and "global"
  207.  *                commands.
  208.  * VAR_UNDEFINED -        1 means that the variable is currently
  209.  *                undefined.  Undefined variables usually
  210.  *                go away completely, but if an undefined
  211.  *                variable has a trace on it, or if it is
  212.  *                a global variable being used by a procedure,
  213.  *                then it stays around even when undefined.
  214.  * VAR_TRACE_ACTIVE -        1 means that trace processing is currently
  215.  *                underway for a read or write access, so
  216.  *                new read or write accesses should not cause
  217.  *                trace procedures to be called and the
  218.  *                variable can't be deleted.
  219.  */
  220.  
  221. #define VAR_ARRAY        1
  222. #define VAR_UPVAR        2
  223. #define VAR_UNDEFINED        4
  224. #define VAR_TRACE_ACTIVE    0x10
  225.  
  226. /*
  227.  *----------------------------------------------------------------
  228.  * Data structures related to procedures.   These are used primarily
  229.  * in tclProc.c
  230.  *----------------------------------------------------------------
  231.  */
  232.  
  233. /*
  234.  * The structure below defines an argument to a procedure, which
  235.  * consists of a name and an (optional) default value.
  236.  */
  237.  
  238. typedef struct Arg {
  239.     struct Arg *nextPtr;    /* Next argument for this procedure,
  240.                  * or NULL if this is the last argument. */
  241.     char *defValue;        /* Pointer to arg's default value, or NULL
  242.                  * if no default value. */
  243.     char name[4];        /* Name of argument starts here.  The name
  244.                  * is followed by space for the default,
  245.                  * if there is one.  The actual size of this
  246.                  * field will be as large as necessary to
  247.                  * hold both name and default value.  THIS
  248.                  * MUST BE THE LAST FIELD IN THE STRUCTURE!! */
  249. } Arg;
  250.  
  251. /*
  252.  * The structure below defines a command procedure, which consists of
  253.  * a collection of Tcl commands plus information about arguments and
  254.  * variables.
  255.  */
  256.  
  257. typedef struct Proc {
  258.     struct Interp *iPtr;    /* Interpreter for which this command
  259.                  * is defined. */
  260.     int refCount;        /* Reference count:  1 if still present
  261.                  * in command table plus 1 for each call
  262.                  * to the procedure that is currently
  263.                  * active.  This structure can be freed
  264.                  * when refCount becomes zero. */
  265.     char *command;        /* Command that constitutes the body of
  266.                  * the procedure (dynamically allocated). */
  267.     Arg *argPtr;        /* Pointer to first of procedure's formal
  268.                  * arguments, or NULL if none. */
  269. } Proc;
  270.  
  271. /*
  272.  * The structure below defines a command trace.  This is used to allow Tcl
  273.  * clients to find out whenever a command is about to be executed.
  274.  */
  275.  
  276. typedef struct Trace {
  277.     int level;            /* Only trace commands at nesting level
  278.                  * less than or equal to this. */
  279.     Tcl_CmdTraceProc *proc;    /* Procedure to call to trace command. */
  280.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  281.     struct Trace *nextPtr;    /* Next in list of traces for this interp. */
  282. } Trace;
  283.  
  284. /*
  285.  * The stucture below defines a deletion callback, which is
  286.  * a procedure to invoke just before an interpreter is deleted.
  287.  */
  288.  
  289. typedef struct DeleteCallback {
  290.     Tcl_InterpDeleteProc *proc;    /* Procedure to call. */
  291.     ClientData clientData;    /* Value to pass to procedure. */
  292.     struct DeleteCallback *nextPtr;
  293.                 /* Next in list of callbacks for this
  294.                  * interpreter (or NULL for end of list). */
  295. } DeleteCallback;
  296.  
  297. /*
  298.  * The structure below defines a frame, which is a procedure invocation.
  299.  * These structures exist only while procedures are being executed, and
  300.  * provide a sort of call stack.
  301.  */
  302.  
  303. typedef struct CallFrame {
  304.     Tcl_HashTable varTable;    /* Hash table containing all of procedure's
  305.                  * local variables. */
  306.     int level;            /* Level of this procedure, for "uplevel"
  307.                  * purposes (i.e. corresponds to nesting of
  308.                  * callerVarPtr's, not callerPtr's).  1 means
  309.                  * outer-most procedure, 0 means top-level. */
  310.     int argc;            /* This and argv below describe name and
  311.                  * arguments for this procedure invocation. */
  312.     char **argv;        /* Array of arguments. */
  313.     struct CallFrame *callerPtr;
  314.                 /* Value of interp->framePtr when this
  315.                  * procedure was invoked (i.e. next in
  316.                  * stack of all active procedures). */
  317.     struct CallFrame *callerVarPtr;
  318.                 /* Value of interp->varFramePtr when this
  319.                  * procedure was invoked (i.e. determines
  320.                  * variable scoping within caller;  same
  321.                  * as callerPtr unless an "uplevel" command
  322.                  * or something equivalent was active in
  323.                  * the caller). */
  324. } CallFrame;
  325.  
  326. /*
  327.  * The structure below defines one history event (a previously-executed
  328.  * command that can be re-executed in whole or in part).
  329.  */
  330.  
  331. typedef struct {
  332.     char *command;        /* String containing previously-executed
  333.                  * command. */
  334.     int bytesAvl;        /* Total # of bytes available at *event (not
  335.                  * all are necessarily in use now). */
  336. } HistoryEvent;
  337.  
  338. /*
  339.  *----------------------------------------------------------------
  340.  * Data structures related to history.   These are used primarily
  341.  * in tclHistory.c
  342.  *----------------------------------------------------------------
  343.  */
  344.  
  345. /*
  346.  * The structure below defines a pending revision to the most recent
  347.  * history event.  Changes are linked together into a list and applied
  348.  * during the next call to Tcl_RecordHistory.  See the comments at the
  349.  * beginning of tclHistory.c for information on revisions.
  350.  */
  351.  
  352. typedef struct HistoryRev {
  353.     int firstIndex;        /* Index of the first byte to replace in
  354.                  * current history event. */
  355.     int lastIndex;        /* Index of last byte to replace in
  356.                  * current history event. */
  357.     int newSize;        /* Number of bytes in newBytes. */
  358.     char *newBytes;        /* Replacement for the range given by
  359.                  * firstIndex and lastIndex. */
  360.     struct HistoryRev *nextPtr;    /* Next in chain of revisions to apply, or
  361.                  * NULL for end of list. */
  362. } HistoryRev;
  363.  
  364. /*
  365.  *----------------------------------------------------------------
  366.  * Data structures related to files.  These are used primarily in
  367.  * tclUnixUtil.c and tclUnixAZ.c.
  368.  *----------------------------------------------------------------
  369.  */
  370.  
  371. /*
  372.  * The data structure below defines an open file (or connection to
  373.  * a process pipeline) as returned by the "open" command.
  374.  */
  375.  
  376. typedef struct OpenFile {
  377.     FILE *f;            /* Stdio file to use for reading and/or
  378.                  * writing. */
  379.     FILE *f2;            /* Normally NULL.  In the special case of
  380.                  * a command pipeline with pipes for both
  381.                  * input and output, this is a stdio file
  382.                  * to use for writing to the pipeline. */
  383.     int readable;        /* Non-zero means file may be read. */
  384.     int writable;        /* Non-zero means file may be written. */
  385.     int numPids;        /* If this is a connection to a process
  386.                  * pipeline, gives number of processes
  387.                  * in pidPtr array below;  otherwise it
  388.                  * is 0. */
  389.     int *pidPtr;        /* Pointer to malloc-ed array of child
  390.                  * process ids (numPids of them), or NULL
  391.                  * if this isn't a connection to a process
  392.                  * pipeline. */
  393.     int errorId;        /* File id of file that receives error
  394.                  * output from pipeline.  -1 means not
  395.                  * used (i.e. this is a normal file). */
  396. } OpenFile;
  397.  
  398. /*
  399.  *----------------------------------------------------------------
  400.  * Data structures related to expressions.  These are used only in
  401.  * tclExpr.c.
  402.  *----------------------------------------------------------------
  403.  */
  404.  
  405. /*
  406.  * The data structure below defines a math function (e.g. sin or hypot)
  407.  * for use in Tcl expressions.
  408.  */
  409.  
  410. #define MAX_MATH_ARGS 5
  411. typedef struct MathFunc {
  412.     int numArgs;        /* Number of arguments for function. */
  413.     Tcl_ValueType argTypes[MAX_MATH_ARGS];
  414.                 /* Acceptable types for each argument. */
  415.     Tcl_MathProc *proc;        /* Procedure that implements this function. */
  416.     ClientData clientData;    /* Additional argument to pass to the function
  417.                  * when invoking it. */
  418. } MathFunc;
  419.  
  420. /*
  421.  *----------------------------------------------------------------
  422.  * This structure defines an interpreter, which is a collection of
  423.  * commands plus other state information related to interpreting
  424.  * commands, such as variable storage.  Primary responsibility for
  425.  * this data structure is in tclBasic.c, but almost every Tcl
  426.  * source file uses something in here.
  427.  *----------------------------------------------------------------
  428.  */
  429.  
  430. typedef struct Command {
  431.     Tcl_CmdProc *proc;        /* Procedure to process command. */
  432.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  433.     Tcl_CmdDeleteProc *deleteProc;
  434.                 /* Procedure to invoke when deleting
  435.                  * command. */
  436.     ClientData deleteData;    /* Arbitrary value to pass to deleteProc
  437.                  * (usually the same as clientData). */
  438. } Command;
  439.  
  440. #define CMD_SIZE(nameLength) ((unsigned) sizeof(Command) + nameLength - 3)
  441.  
  442. typedef struct Interp {
  443.  
  444.     /*
  445.      * Note:  the first three fields must match exactly the fields in
  446.      * a Tcl_Interp struct (see tcl.h).  If you change one, be sure to
  447.      * change the other.
  448.      */
  449.  
  450.     char *result;        /* Points to result returned by last
  451.                  * command. */
  452.     Tcl_FreeProc *freeProc;    /* Zero means result is statically allocated.
  453.                  * If non-zero, gives address of procedure
  454.                  * to invoke to free the result.  Must be
  455.                  * freed by Tcl_Eval before executing next
  456.                  * command. */
  457.     int errorLine;        /* When TCL_ERROR is returned, this gives
  458.                  * the line number within the command where
  459.                  * the error occurred (1 means first line). */
  460.     Tcl_HashTable commandTable;    /* Contains all of the commands currently
  461.                  * registered in this interpreter.  Indexed
  462.                  * by strings; values have type (Command *). */
  463.     Tcl_HashTable mathFuncTable;/* Contains all of the math functions currently
  464.                  * defined for the interpreter.  Indexed by
  465.                  * strings (function names);  values have
  466.                  * type (MathFunc *). */
  467.  
  468.     /*
  469.      * Information related to procedures and variables.  See tclProc.c
  470.      * and tclvar.c for usage.
  471.      */
  472.  
  473.     Tcl_HashTable globalTable;    /* Contains all global variables for
  474.                  * interpreter. */
  475.     int numLevels;        /* Keeps track of how many nested calls to
  476.                  * Tcl_Eval are in progress for this
  477.                  * interpreter.  It's used to delay deletion
  478.                  * of the table until all Tcl_Eval invocations
  479.                  * are completed. */
  480.     int maxNestingDepth;    /* If numLevels exceeds this value then Tcl
  481.                  * assumes that infinite recursion has
  482.                  * occurred and it generates an error. */
  483.     CallFrame *framePtr;    /* Points to top-most in stack of all nested
  484.                  * procedure invocations.  NULL means there
  485.                  * are no active procedures. */
  486.     CallFrame *varFramePtr;    /* Points to the call frame whose variables
  487.                  * are currently in use (same as framePtr
  488.                  * unless an "uplevel" command is being
  489.                  * executed).  NULL means no procedure is
  490.                  * active or "uplevel 0" is being exec'ed. */
  491.     ActiveVarTrace *activeTracePtr;
  492.                 /* First in list of active traces for interp,
  493.                  * or NULL if no active traces. */
  494.     int returnCode;        /* Completion code to return if current
  495.                  * procedure exits with a TCL_RETURN code. */
  496.  
  497.     /*
  498.      * Information related to history:
  499.      */
  500.  
  501.     int numEvents;        /* Number of previously-executed commands
  502.                  * to retain. */
  503.     HistoryEvent *events;    /* Array containing numEvents entries
  504.                  * (dynamically allocated). */
  505.     int curEvent;        /* Index into events of place where current
  506.                  * (or most recent) command is recorded. */
  507.     int curEventNum;        /* Event number associated with the slot
  508.                  * given by curEvent. */
  509.     HistoryRev *revPtr;        /* First in list of pending revisions. */
  510.     char *historyFirst;        /* First char. of current command executed
  511.                  * from history module or NULL if none. */
  512.     int revDisables;        /* 0 means history revision OK;  > 0 gives
  513.                  * a count of number of times revision has
  514.                  * been disabled. */
  515.     char *evalFirst;        /* If TCL_RECORD_BOUNDS flag set, Tcl_Eval
  516.                  * sets this field to point to the first
  517.                  * char. of text from which the current
  518.                  * command came.  Otherwise Tcl_Eval sets
  519.                  * this to NULL. */
  520.     char *evalLast;        /* Similar to evalFirst, except points to
  521.                  * last character of current command. */
  522.  
  523.     /*
  524.      * Information used by Tcl_AppendResult to keep track of partial
  525.      * results.  See Tcl_AppendResult code for details.
  526.      */
  527.  
  528.     char *appendResult;        /* Storage space for results generated
  529.                  * by Tcl_AppendResult.  Malloc-ed.  NULL
  530.                  * means not yet allocated. */
  531.     int appendAvl;        /* Total amount of space available at
  532.                  * partialResult. */
  533.     int appendUsed;        /* Number of non-null bytes currently
  534.                  * stored at partialResult. */
  535.  
  536.     /*
  537.      * Information related to files.  See tclUnixAZ.c and tclUnixUtil.c
  538.      * for details.
  539.      */
  540.  
  541.     int numFiles;        /* Number of entries in oFilePtrArray
  542.                  * below.  0 means array hasn't been
  543.                  * created yet. */
  544.     OpenFile **oFilePtrArray;    /* Pointer to malloc-ed array of pointers
  545.                  * to information about open files.  Entry
  546.                  * N corresponds to the file with fileno N.
  547.                  * If an entry is NULL then the corresponding
  548.                  * file isn't open.  If oFilePtrArray is NULL
  549.                  * it means no files have been used, so even
  550.                  * stdin/stdout/stderr entries haven't been
  551.                  * setup yet. */
  552.  
  553.     /*
  554.      * A cache of compiled regular expressions.  See TclCompileRegexp
  555.      * in tclUtil.c for details.
  556.      */
  557.  
  558. #define NUM_REGEXPS 5
  559.     char *patterns[NUM_REGEXPS];/* Strings corresponding to compiled
  560.                  * regular expression patterns.  NULL
  561.                  * means that this slot isn't used.
  562.                  * Malloc-ed. */
  563.     int patLengths[NUM_REGEXPS];/* Number of non-null characters in
  564.                  * corresponding entry in patterns.
  565.                  * -1 means entry isn't used. */
  566.     regexp *regexps[NUM_REGEXPS];
  567.                 /* Compiled forms of above strings.  Also
  568.                  * malloc-ed, or NULL if not in use yet. */
  569.  
  570.     /*
  571.      * Information used by Tcl_PrintDouble:
  572.      */
  573.  
  574.     char pdFormat[10];        /* Format string used by Tcl_PrintDouble. */
  575.     int pdPrec;            /* Current precision (used to restore the
  576.                  * the tcl_precision variable after a bogus
  577.                  * value has been put into it). */
  578.  
  579.     /*
  580.      * Miscellaneous information:
  581.      */
  582.  
  583.     int cmdCount;        /* Total number of times a command procedure
  584.                  * has been called for this interpreter. */
  585.     int noEval;            /* Non-zero means no commands should actually
  586.                  * be executed:  just parse only.  Used in
  587.                  * expressions when the result is already
  588.                  * determined. */
  589.     int evalFlags;        /* Flags to control next call to Tcl_Eval.
  590.                  * Normally zero, but may be set before
  591.                  * calling Tcl_Eval to an OR'ed combination
  592.                  * of TCL_BRACKET_TERM and TCL_RECORD_BOUNDS. */
  593.     char *termPtr;        /* Character just after the last one in
  594.                  * a command.  Set by Tcl_Eval before
  595.                  * returning. */
  596.     char *scriptFile;        /* NULL means there is no nested source
  597.                  * command active;  otherwise this points to
  598.                  * the name of the file being sourced (it's
  599.                  * not malloc-ed:  it points to an argument
  600.                  * to Tcl_EvalFile. */
  601.     int flags;            /* Various flag bits.  See below. */
  602.     Trace *tracePtr;        /* List of traces for this interpreter. */
  603.     DeleteCallback *deleteCallbackPtr;
  604.                 /* First in list of callbacks to invoke when
  605.                  * interpeter is deleted. */
  606.     char resultSpace[TCL_RESULT_SIZE+1];
  607.                 /* Static space for storing small results. */
  608. } Interp;
  609.  
  610. /*
  611.  * Flag bits for Interp structures:
  612.  *
  613.  * DELETED:        Non-zero means the interpreter has been deleted:
  614.  *            don't process any more commands for it, and destroy
  615.  *            the structure as soon as all nested invocations of
  616.  *            Tcl_Eval are done.
  617.  * ERR_IN_PROGRESS:    Non-zero means an error unwind is already in progress.
  618.  *            Zero means a command proc has been invoked since last
  619.  *            error occured.
  620.  * ERR_ALREADY_LOGGED:    Non-zero means information has already been logged
  621.  *            in $errorInfo for the current Tcl_Eval instance,
  622.  *            so Tcl_Eval needn't log it (used to implement the
  623.  *            "error message log" command).
  624.  * ERROR_CODE_SET:    Non-zero means that Tcl_SetErrorCode has been
  625.  *            called to record information for the current
  626.  *            error.  Zero means Tcl_Eval must clear the
  627.  *            errorCode variable if an error is returned.
  628.  * EXPR_INITIALIZED:    1 means initialization specific to expressions has
  629.  *            been carried out.
  630.  */
  631.  
  632. #define DELETED            1
  633. #define ERR_IN_PROGRESS        2
  634. #define ERR_ALREADY_LOGGED    4
  635. #define ERROR_CODE_SET        8
  636. #define EXPR_INITIALIZED    0x10
  637.  
  638. /*
  639.  * Default value for the pdPrec and pdFormat fields of interpreters:
  640.  */
  641.  
  642. #define DEFAULT_PD_PREC 6
  643. #define DEFAULT_PD_FORMAT "%g"
  644.  
  645. /*
  646.  *----------------------------------------------------------------
  647.  * Data structures related to command parsing.   These are used in
  648.  * tclParse.c and its clients.
  649.  *----------------------------------------------------------------
  650.  */
  651.  
  652. /*
  653.  * The following data structure is used by various parsing procedures
  654.  * to hold information about where to store the results of parsing
  655.  * (e.g. the substituted contents of a quoted argument, or the result
  656.  * of a nested command).  At any given time, the space available
  657.  * for output is fixed, but a procedure may be called to expand the
  658.  * space available if the current space runs out.
  659.  */
  660.  
  661. typedef struct ParseValue {
  662.     char *buffer;        /* Address of first character in
  663.                  * output buffer. */
  664.     char *next;            /* Place to store next character in
  665.                  * output buffer. */
  666.     char *end;            /* Address of the last usable character
  667.                  * in the buffer. */
  668.     void (*expandProc) _ANSI_ARGS_((struct ParseValue *pvPtr, int needed));
  669.                 /* Procedure to call when space runs out;
  670.                  * it will make more space. */
  671.     ClientData clientData;    /* Arbitrary information for use of
  672.                  * expandProc. */
  673. } ParseValue;
  674.  
  675. /*
  676.  * A table used to classify input characters to assist in parsing
  677.  * Tcl commands.  The table should be indexed with a signed character
  678.  * using the CHAR_TYPE macro.  The character may have a negative
  679.  * value.
  680.  */
  681.  
  682. extern char tclTypeTable[];
  683. #define CHAR_TYPE(c) (tclTypeTable+128)[c]
  684.  
  685. /*
  686.  * Possible values returned by CHAR_TYPE:
  687.  *
  688.  * TCL_NORMAL -        All characters that don't have special significance
  689.  *            to the Tcl language.
  690.  * TCL_SPACE -        Character is space, tab, or return.
  691.  * TCL_COMMAND_END -    Character is newline or null or semicolon or
  692.  *            close-bracket.
  693.  * TCL_QUOTE -        Character is a double-quote.
  694.  * TCL_OPEN_BRACKET -    Character is a "[".
  695.  * TCL_OPEN_BRACE -    Character is a "{".
  696.  * TCL_CLOSE_BRACE -    Character is a "}".
  697.  * TCL_BACKSLASH -    Character is a "\".
  698.  * TCL_DOLLAR -        Character is a "$".
  699.  */
  700.  
  701. #define TCL_NORMAL        0
  702. #define TCL_SPACE        1
  703. #define TCL_COMMAND_END        2
  704. #define TCL_QUOTE        3
  705. #define TCL_OPEN_BRACKET    4
  706. #define TCL_OPEN_BRACE        5
  707. #define TCL_CLOSE_BRACE        6
  708. #define TCL_BACKSLASH        7
  709. #define TCL_DOLLAR        8
  710.  
  711. /*
  712.  * Additional flags passed to Tcl_Eval.  See tcl.h for other flags to
  713.  * Tcl_Eval;  these ones are only used internally by Tcl.
  714.  *
  715.  * TCL_RECORD_BOUNDS    Tells Tcl_Eval to record information in the
  716.  *            evalFirst and evalLast fields for each command
  717.  *            executed directly from the string (top-level
  718.  *            commands and those from command substitution).
  719.  */
  720.  
  721. #define TCL_RECORD_BOUNDS    0x100
  722.  
  723. /*
  724.  * Maximum number of levels of nesting permitted in Tcl commands (used
  725.  * to catch infinite recursion).
  726.  */
  727.  
  728. #define MAX_NESTING_DEPTH    1000
  729.  
  730. /*
  731.  * Variables shared among Tcl modules but not used by the outside
  732.  * world:
  733.  */
  734.  
  735. extern char *        tclRegexpError;
  736.  
  737. /*
  738.  *----------------------------------------------------------------
  739.  * Procedures shared among Tcl modules but not used by the outside
  740.  * world:
  741.  *----------------------------------------------------------------
  742.  */
  743.  
  744. extern void        panic();
  745. extern regexp *        TclCompileRegexp _ANSI_ARGS_((Tcl_Interp *interp,
  746.                 char *string));
  747. extern void        TclCopyAndCollapse _ANSI_ARGS_((int count, char *src,
  748.                 char *dst));
  749. extern void        TclDeleteVars _ANSI_ARGS_((Interp *iPtr,
  750.                 Tcl_HashTable *tablePtr));
  751. extern void        TclExpandParseValue _ANSI_ARGS_((ParseValue *pvPtr,
  752.                 int needed));
  753. extern int        TclFindElement _ANSI_ARGS_((Tcl_Interp *interp,
  754.                 char *list, char **elementPtr, char **nextPtr,
  755.                 int *sizePtr, int *bracePtr));
  756. extern Proc *        TclFindProc _ANSI_ARGS_((Interp *iPtr,
  757.                 char *procName));
  758. extern int        TclGetFrame _ANSI_ARGS_((Tcl_Interp *interp,
  759.                 char *string, CallFrame **framePtrPtr));
  760. extern int        TclGetListIndex _ANSI_ARGS_((Tcl_Interp *interp,
  761.                 char *string, int *indexPtr));
  762. extern Proc *        TclIsProc _ANSI_ARGS_((Command *cmdPtr));
  763. extern int        TclParseBraces _ANSI_ARGS_((Tcl_Interp *interp,
  764.                 char *string, char **termPtr, ParseValue *pvPtr));
  765. extern int        TclParseNestedCmd _ANSI_ARGS_((Tcl_Interp *interp,
  766.                 char *string, int flags, char **termPtr,
  767.                 ParseValue *pvPtr));
  768. extern int        TclParseQuotes _ANSI_ARGS_((Tcl_Interp *interp,
  769.                 char *string, int termChar, int flags,
  770.                 char **termPtr, ParseValue *pvPtr));
  771. extern int        TclParseWords _ANSI_ARGS_((Tcl_Interp *interp,
  772.                 char *string, int flags, int maxWords,
  773.                 char **termPtr, int *argcPtr, char **argv,
  774.                 ParseValue *pvPtr));
  775. extern char *        TclPrecTraceProc _ANSI_ARGS_((ClientData clientData,
  776.                 Tcl_Interp *interp, char *name1, char *name2,
  777.                 int flags));
  778. extern void        TclSetupEnv _ANSI_ARGS_((Tcl_Interp *interp));
  779. extern char *        TclWordEnd _ANSI_ARGS_((char *start, int nested));
  780.  
  781. /*
  782.  *----------------------------------------------------------------
  783.  * Command procedures in the generic core:
  784.  *----------------------------------------------------------------
  785.  */
  786.  
  787. extern int    Tcl_AppendCmd _ANSI_ARGS_((ClientData clientData,
  788.             Tcl_Interp *interp, int argc, char **argv));
  789. extern int    Tcl_ArrayCmd _ANSI_ARGS_((ClientData clientData,
  790.             Tcl_Interp *interp, int argc, char **argv));
  791. extern int    Tcl_BreakCmd _ANSI_ARGS_((ClientData clientData,
  792.             Tcl_Interp *interp, int argc, char **argv));
  793. extern int    Tcl_CaseCmd _ANSI_ARGS_((ClientData clientData,
  794.             Tcl_Interp *interp, int argc, char **argv));
  795. extern int    Tcl_CatchCmd _ANSI_ARGS_((ClientData clientData,
  796.             Tcl_Interp *interp, int argc, char **argv));
  797. extern int    Tcl_ConcatCmd _ANSI_ARGS_((ClientData clientData,
  798.             Tcl_Interp *interp, int argc, char **argv));
  799. extern int    Tcl_ContinueCmd _ANSI_ARGS_((ClientData clientData,
  800.             Tcl_Interp *interp, int argc, char **argv));
  801. extern int    Tcl_ErrorCmd _ANSI_ARGS_((ClientData clientData,
  802.             Tcl_Interp *interp, int argc, char **argv));
  803. extern int    Tcl_EvalCmd _ANSI_ARGS_((ClientData clientData,
  804.             Tcl_Interp *interp, int argc, char **argv));
  805. extern int    Tcl_ExprCmd _ANSI_ARGS_((ClientData clientData,
  806.             Tcl_Interp *interp, int argc, char **argv));
  807. extern int    Tcl_ForCmd _ANSI_ARGS_((ClientData clientData,
  808.             Tcl_Interp *interp, int argc, char **argv));
  809. extern int    Tcl_ForeachCmd _ANSI_ARGS_((ClientData clientData,
  810.             Tcl_Interp *interp, int argc, char **argv));
  811. extern int    Tcl_FormatCmd _ANSI_ARGS_((ClientData clientData,
  812.             Tcl_Interp *interp, int argc, char **argv));
  813. extern int    Tcl_GlobalCmd _ANSI_ARGS_((ClientData clientData,
  814.             Tcl_Interp *interp, int argc, char **argv));
  815. extern int    Tcl_HistoryCmd _ANSI_ARGS_((ClientData clientData,
  816.             Tcl_Interp *interp, int argc, char **argv));
  817. extern int    Tcl_IfCmd _ANSI_ARGS_((ClientData clientData,
  818.             Tcl_Interp *interp, int argc, char **argv));
  819. extern int    Tcl_IncrCmd _ANSI_ARGS_((ClientData clientData,
  820.             Tcl_Interp *interp, int argc, char **argv));
  821. extern int    Tcl_InfoCmd _ANSI_ARGS_((ClientData clientData,
  822.             Tcl_Interp *interp, int argc, char **argv));
  823. extern int    Tcl_JoinCmd _ANSI_ARGS_((ClientData clientData,
  824.             Tcl_Interp *interp, int argc, char **argv));
  825. extern int    Tcl_LappendCmd _ANSI_ARGS_((ClientData clientData,
  826.             Tcl_Interp *interp, int argc, char **argv));
  827. extern int    Tcl_LindexCmd _ANSI_ARGS_((ClientData clientData,
  828.             Tcl_Interp *interp, int argc, char **argv));
  829. extern int    Tcl_LinsertCmd _ANSI_ARGS_((ClientData clientData,
  830.             Tcl_Interp *interp, int argc, char **argv));
  831. extern int    Tcl_LlengthCmd _ANSI_ARGS_((ClientData clientData,
  832.             Tcl_Interp *interp, int argc, char **argv));
  833. extern int    Tcl_ListCmd _ANSI_ARGS_((ClientData clientData,
  834.             Tcl_Interp *interp, int argc, char **argv));
  835. extern int    Tcl_LrangeCmd _ANSI_ARGS_((ClientData clientData,
  836.             Tcl_Interp *interp, int argc, char **argv));
  837. extern int    Tcl_LreplaceCmd _ANSI_ARGS_((ClientData clientData,
  838.             Tcl_Interp *interp, int argc, char **argv));
  839. extern int    Tcl_LsearchCmd _ANSI_ARGS_((ClientData clientData,
  840.             Tcl_Interp *interp, int argc, char **argv));
  841. extern int    Tcl_LsortCmd _ANSI_ARGS_((ClientData clientData,
  842.             Tcl_Interp *interp, int argc, char **argv));
  843. extern int    Tcl_ProcCmd _ANSI_ARGS_((ClientData clientData,
  844.             Tcl_Interp *interp, int argc, char **argv));
  845. extern int    Tcl_RegexpCmd _ANSI_ARGS_((ClientData clientData,
  846.             Tcl_Interp *interp, int argc, char **argv));
  847. extern int    Tcl_RegsubCmd _ANSI_ARGS_((ClientData clientData,
  848.             Tcl_Interp *interp, int argc, char **argv));
  849. extern int    Tcl_RenameCmd _ANSI_ARGS_((ClientData clientData,
  850.             Tcl_Interp *interp, int argc, char **argv));
  851. extern int    Tcl_ReturnCmd _ANSI_ARGS_((ClientData clientData,
  852.             Tcl_Interp *interp, int argc, char **argv));
  853. extern int    Tcl_ScanCmd _ANSI_ARGS_((ClientData clientData,
  854.             Tcl_Interp *interp, int argc, char **argv));
  855. extern int    Tcl_SetCmd _ANSI_ARGS_((ClientData clientData,
  856.             Tcl_Interp *interp, int argc, char **argv));
  857. extern int    Tcl_SplitCmd _ANSI_ARGS_((ClientData clientData,
  858.             Tcl_Interp *interp, int argc, char **argv));
  859. extern int    Tcl_StringCmd _ANSI_ARGS_((ClientData clientData,
  860.             Tcl_Interp *interp, int argc, char **argv));
  861. extern int    Tcl_SwitchCmd _ANSI_ARGS_((ClientData clientData,
  862.             Tcl_Interp *interp, int argc, char **argv));
  863. extern int    Tcl_TraceCmd _ANSI_ARGS_((ClientData clientData,
  864.             Tcl_Interp *interp, int argc, char **argv));
  865. extern int    Tcl_UnsetCmd _ANSI_ARGS_((ClientData clientData,
  866.             Tcl_Interp *interp, int argc, char **argv));
  867. extern int    Tcl_UplevelCmd _ANSI_ARGS_((ClientData clientData,
  868.             Tcl_Interp *interp, int argc, char **argv));
  869. extern int    Tcl_UpvarCmd _ANSI_ARGS_((ClientData clientData,
  870.             Tcl_Interp *interp, int argc, char **argv));
  871. extern int    Tcl_WhileCmd _ANSI_ARGS_((ClientData clientData,
  872.             Tcl_Interp *interp, int argc, char **argv));
  873. extern int    Tcl_Cmd _ANSI_ARGS_((ClientData clientData,
  874.             Tcl_Interp *interp, int argc, char **argv));
  875. extern int    Tcl_Cmd _ANSI_ARGS_((ClientData clientData,
  876.             Tcl_Interp *interp, int argc, char **argv));
  877.  
  878. /*
  879.  *----------------------------------------------------------------
  880.  * Command procedures in the UNIX core:
  881.  *----------------------------------------------------------------
  882.  */
  883.  
  884. extern int    Tcl_CdCmd _ANSI_ARGS_((ClientData clientData,
  885.             Tcl_Interp *interp, int argc, char **argv));
  886. extern int    Tcl_CloseCmd _ANSI_ARGS_((ClientData clientData,
  887.             Tcl_Interp *interp, int argc, char **argv));
  888. extern int    Tcl_EofCmd _ANSI_ARGS_((ClientData clientData,
  889.             Tcl_Interp *interp, int argc, char **argv));
  890. extern int    Tcl_ExecCmd _ANSI_ARGS_((ClientData clientData,
  891.             Tcl_Interp *interp, int argc, char **argv));
  892. extern int    Tcl_ExitCmd _ANSI_ARGS_((ClientData clientData,
  893.             Tcl_Interp *interp, int argc, char **argv));
  894. extern int    Tcl_FileCmd _ANSI_ARGS_((ClientData clientData,
  895.             Tcl_Interp *interp, int argc, char **argv));
  896. extern int    Tcl_FlushCmd _ANSI_ARGS_((ClientData clientData,
  897.             Tcl_Interp *interp, int argc, char **argv));
  898. extern int    Tcl_GetsCmd _ANSI_ARGS_((ClientData clientData,
  899.             Tcl_Interp *interp, int argc, char **argv));
  900. extern int    Tcl_GlobCmd _ANSI_ARGS_((ClientData clientData,
  901.             Tcl_Interp *interp, int argc, char **argv));
  902. extern int    Tcl_OpenCmd _ANSI_ARGS_((ClientData clientData,
  903.             Tcl_Interp *interp, int argc, char **argv));
  904. extern int    Tcl_PutsCmd _ANSI_ARGS_((ClientData clientData,
  905.             Tcl_Interp *interp, int argc, char **argv));
  906. extern int    Tcl_PidCmd _ANSI_ARGS_((ClientData clientData,
  907.             Tcl_Interp *interp, int argc, char **argv));
  908. extern int    Tcl_PwdCmd _ANSI_ARGS_((ClientData clientData,
  909.             Tcl_Interp *interp, int argc, char **argv));
  910. extern int    Tcl_ReadCmd _ANSI_ARGS_((ClientData clientData,
  911.             Tcl_Interp *interp, int argc, char **argv));
  912. extern int    Tcl_SeekCmd _ANSI_ARGS_((ClientData clientData,
  913.             Tcl_Interp *interp, int argc, char **argv));
  914. extern int    Tcl_SourceCmd _ANSI_ARGS_((ClientData clientData,
  915.             Tcl_Interp *interp, int argc, char **argv));
  916. extern int    Tcl_TellCmd _ANSI_ARGS_((ClientData clientData,
  917.             Tcl_Interp *interp, int argc, char **argv));
  918. extern int    Tcl_TimeCmd _ANSI_ARGS_((ClientData clientData,
  919.             Tcl_Interp *interp, int argc, char **argv));
  920.  
  921. #endif /* _TCLINT */
  922.